Skip to content

feat: replace pi-based filesystem tools with native implementation#363

Closed
shadowfax92 wants to merge 4 commits intomainfrom
feat/remove-pi-mono-depdency-codex
Closed

feat: replace pi-based filesystem tools with native implementation#363
shadowfax92 wants to merge 4 commits intomainfrom
feat/remove-pi-mono-depdency-codex

Conversation

@shadowfax92
Copy link
Contributor

@shadowfax92 shadowfax92 commented Feb 25, 2026

Summary

  • Replace the @mariozechner/pi-agent-core + @mariozechner/pi-coding-agent filesystem tool adapter in apps/server with native in-repo tools.
  • Preserve existing filesystem_* tool names and chat-mode behavior while adding explicit session-directory boundary checks and bounded output handling.
  • Add focused filesystem tool tests (path utils, truncation, edit behavior) and remove obsolete pi dependencies from apps/server/package.json.

Design

This change keeps the existing ToolLoopAgent integration seam intact (AiSdkAgent still composes browser tools, external MCP tools, and filesystem tools), but swaps the filesystem layer to a modular native implementation under apps/server/src/agent/tool-loop/filesystem-tools/. The new structure follows pi-mono’s small-per-tool module style while applying stricter safety constraints inspired by Gemini CLI, including consistent path validation, deterministic limits/truncation, and normalized model output mapping.

Test plan

  • bun run --filter @browseros/server typecheck
  • bun test apps/server/tests/agent/filesystem-tools
  • bun test apps/server/tests (contains existing unrelated failures in this repo; this change does not modify those areas)

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 25, 2026

Greptile Summary

Successfully replaces pi-based filesystem tools with a native in-repo implementation while preserving existing tool names and behavior.

Key improvements:

  • Removed external dependencies (@mariozechner/pi-agent-core and @mariozechner/pi-coding-agent)
  • Added comprehensive security with symlink resolution and session directory boundary checks
  • Implemented deterministic output limits and truncation (2000 lines, 50KB)
  • Added focused test coverage with 35/36 tests passing (1 test fails only due to environment lacking sleep command)
  • Follows project conventions: kebab-case file naming, extensionless imports, minimal comments

Implementation quality:

  • Clean modular architecture with separation of concerns
  • Type-safe with Zod schemas for all tool inputs
  • Proper error handling throughout
  • Well-defined exported constants for tool limits
  • UTF-8 boundary-aware truncation
  • Cross-platform shell detection (bash/cmd)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • This is a well-architected refactor with comprehensive test coverage (35/36 tests passing), strong security (symlink and path boundary checks), proper error handling, and clean code that follows project conventions. The implementation is modular, type-safe, and thoroughly tested.
  • No files require special attention

Important Files Changed

Filename Overview
apps/server/package.json removed @mariozechner/pi-agent-core and @mariozechner/pi-coding-agent dependencies as they are replaced by native implementation
apps/server/src/tools/filesystem/native-tool-adapter.ts new adapter that wraps native filesystem tools, handles tool execution, metrics logging, and model output conversion
apps/server/src/tools/filesystem/path-utils.ts implements path resolution, symlink security checks, glob pattern matching, and session directory boundary enforcement
apps/server/src/tools/filesystem/read.ts implements file reading with offset/limit support, image detection, truncation, and path boundary validation
apps/server/src/tools/filesystem/edit.ts implements exact text replacement with BOM preservation, line ending detection, and uniqueness validation
apps/server/src/tools/filesystem/grep.ts implements content search with regex support, glob filtering, context lines, binary file detection, and result limits
apps/server/src/tools/filesystem/bash.ts implements shell command execution with timeout support, cross-platform shell detection, and output truncation

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[AiSdkAgent] -->|buildFilesystemToolSet| B[native-tool-adapter]
    B -->|wraps| C[Native Tool Implementations]
    C --> D[read.ts]
    C --> E[write.ts]
    C --> F[edit.ts]
    C --> G[grep.ts]
    C --> H[find.ts]
    C --> I[ls.ts]
    C --> J[bash.ts]
    
    D -->|uses| K[path-utils]
    E -->|uses| K
    F -->|uses| K
    G -->|uses| K
    H -->|uses| K
    I -->|uses| K
    
    D -->|uses| L[truncate]
    G -->|uses| L
    H -->|uses| L
    I -->|uses| L
    J -->|uses| L
    
    K -->|security| M[Path Boundary Checks]
    K -->|security| N[Symlink Resolution]
    
    G -->|uses| O[scan.ts]
    H -->|uses| O
    
    B -->|returns| P[ToolSet]
    P -->|registered as| Q[filesystem_read, filesystem_write, etc]
Loading

Last reviewed commit: c9e638f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant